<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*,java.text.SimpleDateFormat"%>
<jsp:include page="../common/header.jsp"></jsp:include>
<%
UserSession usersession = (UserSession)session.getAttribute("user");
//String ent_id 			= (String)session.getAttribute("ent_id");

String connGroup 	= "";
String user_id 		= "";
if(usersession!=null){
	connGroup 	= CmmUtil.nvl(usersession.getConnGroup(),"0");
	user_id 	= CmmUtil.nvl(usersession.getUser_id(),"");
}

System.out.println("connGroup======>"+connGroup);
System.out.println("user_id======>"+user_id);

/*
String present_Year = String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR));
//GregorianCalendar에서 1월 return 값이 0이므로 Month에는  1을 더해주어야 함
String present_Month = String.valueOf(GregorianCalendar.getInstance().get(Calendar.MONTH)+1); 
String present_Date = String.valueOf(GregorianCalendar.getInstance().get(Calendar.DATE));

if(present_Month.length() == 1){
	present_Month = "0" + present_Month; //01월,02월 ..... 09월
}

GregorianCalendar g = new GregorianCalendar();
g.add(Calendar.MONTH, 0);

String befor_Month = String.valueOf(g.get(Calendar.MONTH));

if(befor_Month.length() == 1){
	befor_Month = "0" + befor_Month; //01월,02월 ..... 09월
}

if(present_Date.length() == 1){
	present_Date = "0" + present_Date; //01일,02일 ..... 09일
}

//start_dt,close_dt,selected_year,selected_month 의 값에 받아오는 인자가 없을 경우 default로 현재 시간을 Setting
String start_dt 		= CmmUtil.nvl(request.getParameter("start_dt"),present_Year + befor_Month + present_Date);
String close_dt 		= CmmUtil.nvl(request.getParameter("close_dt"),present_Year + present_Month + present_Date);
*/

Calendar now = Calendar.getInstance();
String year     = String.valueOf(now.get(Calendar.YEAR));
String month    = String.valueOf(now.get(Calendar.MONTH)+1);
String curDay   = String.valueOf(now.get(Calendar.DATE));

if(month.length() == 1){
	month = 0 + month;
}

if(curDay.length() == 1){
	curDay = 0 + curDay;
}

now.add(Calendar.MONTH,-1);

String b_year     = String.valueOf(now.get(Calendar.YEAR));
String b_month    = String.valueOf(now.get(Calendar.MONTH)+1);
String b_curDay   = String.valueOf(now.get(Calendar.DATE));

if(b_month.length() == 1){
	b_month = 0 + b_month;
}

if(b_curDay.length() == 1){
	b_curDay = 0 + b_curDay;
}

String start_dt = CmmUtil.nvl(request.getParameter("start_dt"),b_year + b_month + b_curDay);
String close_dt = CmmUtil.nvl(request.getParameter("close_dt"),year + month + curDay);

String gubun 		= CmmUtil.nvl(request.getParameter("gubun"),"");

HashMap map_cnt = new HashMap();
HashMap map1_cnt = null;
HashMap map1_cnt2 = null;
ArrayList list_cnt = new ArrayList();	
CommonDaoService commonservice_cnt = new CommonDaoService("ComStuStateDao_pop");
map_cnt.put("connGroup",connGroup);
map_cnt.put("user_id",user_id);	
map_cnt.put("start_dt",start_dt);	
map_cnt.put("close_dt",close_dt);		
list_cnt = (ArrayList)commonservice_cnt.commonDaoMethod(map_cnt);	
System.out.println(list_cnt);



String login_nm = "";
String poi_nm2 = "";
int recommend_rate = 0;
int final_prog_rate = 0;
String conn_dt = "";
String conn_mis = "";
String std_start_dt = "";
String std_close_dt = "";

%>
<body>

<%if(gubun.equals("poorly")) {%>
	<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="main_table4">
       <tr>
          <td class="table_th">이름</td>
          <td class="table_th">과정명</td>
          <td class="table_th">학습일</td>
          <td class="table_th">권장진도율</td>
	      <td class="table_th">진도율</td>
		</tr>
<%
for(int i=0; i<list_cnt.size(); i++){
	map1_cnt 			= (HashMap)list_cnt.get(i); 
	
	login_nm = (String)map1_cnt.get("login_nm");
	poi_nm2 = (String)map1_cnt.get("poi_nm2");
	conn_dt = CmmUtil.nvl((String)map1_cnt.get("conn_dt"),"");
	
	std_start_dt = (String)map1_cnt.get("std_start_dt");
	std_close_dt = (String)map1_cnt.get("std_close_dt");
	
	recommend_rate = Integer.parseInt((String)map1_cnt.get("recommend_rate"));
	final_prog_rate = Integer.parseInt((String)map1_cnt.get("final_prog_rate"));
	
	if(recommend_rate > final_prog_rate){
%>
		<tr>
          <td><%=login_nm %></td>
		  <td><%=poi_nm2 %></td>
          <td><%=std_start_dt + "~" +  std_close_dt%></td>                    
          <td><%=recommend_rate %></td>
		  <td><%=final_prog_rate %></td>
		</tr>
<%	
		}
}
%>
	</table>	
<%}else if(gubun.equals("mis")) { %>
	<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="main_table4">
       <tr>
          <td class="table_th">이름</td>
          <td class="table_th">과정명</td>
          <td class="table_th">학습일</td>
          <td class="table_th">권장진도율</td>
	      <td class="table_th">진도율</td>
		  <td class="table_th">최근접속일</td>
		</tr>
<%
for(int i=0; i<list_cnt.size(); i++){
	map1_cnt 			= (HashMap)list_cnt.get(i); 
	
	login_nm = (String)map1_cnt.get("login_nm");
	poi_nm2 = (String)map1_cnt.get("poi_nm2");
	conn_dt = CmmUtil.nvl((String)map1_cnt.get("conn_dt"),"");
	conn_mis = CmmUtil.nvl((String)map1_cnt.get("conn_mis"),"");
	
	std_start_dt = (String)map1_cnt.get("std_start_dt");
	std_close_dt = (String)map1_cnt.get("std_close_dt");
	
	recommend_rate = Integer.parseInt((String)map1_cnt.get("recommend_rate"));
	final_prog_rate = Integer.parseInt((String)map1_cnt.get("final_prog_rate"));
	
		if(conn_mis.equals("1")){
%>
		<tr>
          <td><%=login_nm %></td>
		  <td><%=poi_nm2 %></td>
          <td><%=std_start_dt + "~" +  std_close_dt%></td>                    
          <td><%=recommend_rate %></td>
		  <td><%=final_prog_rate %></td>
		  <td><%=conn_dt %></td>
		</tr>
<%	
		}
}
%>
	</table>
<%} %>
</body>
</html>